#!/bin/bash
# 
# File:   redis_check.bash
# Author: tangchao
#
# Created on 2013-5-28, 13:47:28
#

ip="172.17.4.49"
port=6379
key="tangchao"
auth=

redis_connect_fail_times=0

cli=bin/ng_redis_cli

if [[ 0 != $? ]];then
    echo "Not found redis-cli."
    exit 1
fi


function restart_redis()
{
    echo "restart redis"
}

function restart_proxy()
{
    service cluster-pr stop
    service cluster-pr start
}


${cli} -h ${ip} -p ${port} -k ${key}


for((i = 0; i < 10; i++));do
    if [[ 0 != $? ]];then
        let "redis_connect_fail_times += 1"
    fi
done

if [[ ${redis_connect_fail_times} == 10 ]];then
    restart_redis
    restart_proxy
fi

